package com.ruoyi.message.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.SmsConstants;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.message.domain.MsgSmsTpl;
import com.ruoyi.message.mapper.MsgSmsTplMapper;
import com.ruoyi.message.service.IMsgSmsTplService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 短信模板Service业务层处理
 *
 * @author ryb
 * @date 2020-12-21
 */
@Service
public class MsgSmsTplServiceImpl extends ServiceImpl<MsgSmsTplMapper, MsgSmsTpl> implements IMsgSmsTplService {

    @Autowired
    RedisService redisService;

    // 获取短信模板
    @Override
    public MsgSmsTpl getSMSTpl(String type) {
        if(redisService.getCacheObject(SmsConstants.CACHE_SMS_TPL) != null) {
            return redisService.getCacheObject(SmsConstants.CACHE_SMS_TPL);
        }
        MsgSmsTpl tpl = this.lambdaQuery().eq(MsgSmsTpl::getType, type).one();
        if(tpl != null) {
            redisService.setCacheObject(SmsConstants.CACHE_SMS_TPL + type, tpl);
        }
        return tpl;
    }

}
